package com.liming;

import org.junit.jupiter.api.Test;

import java.security.Key;
import java.util.Comparator;
import java.util.HashMap;
import java.util.TreeMap;

public class TreeMapDemo {
    public static void main(String[] args) {

    }
    @Test
    public  void test1() {
        TreeMap<Student, String> map = new TreeMap<>(new Comparator<Student>(){
            @Override
            public int compare(Student o1, Student o2) {
                //年龄降序
                return o2.getAge() - o1.getAge();
            }
        });
        map.put(new Student("张三", 20), "北京");
        map.put(new Student("李四", 21), "上海");
        map.put(new Student("王五", 22), "广州");
        map.put(new Student("赵六", 23), "深圳");
        map.put(new Student("田七", 24), "杭州");
        map.forEach((key, value) -> System.out.println(key + " : " + value));

        HashMap<String,String> hashMap = new HashMap<>();
        hashMap.put("肖博文","广安");
        hashMap.put("萧炎","杭州");
        hashMap.put("唐三","上海");
        hashMap.put("小舞","北京");
        hashMap.put("荒天帝","深圳");

    }
    @Test
    public void test0() {
        TreeMap<Student, String> map = new TreeMap<>();
        map.put(new Student("张三", 20), "北京");
        map.put(new Student("李四", 21), "上海");
        map.put(new Student("王五", 22), "广州");
        map.put(new Student("赵六", 23), "深圳");
        map.put(new Student("田七", 24), "杭州");
        map.forEach((key, value) -> System.out.println(key + " : " + value));
    }
}
